package com.pets.springboot_petshop.controller;

import com.pets.springboot_petshop.entity.Pettype;
import com.pets.springboot_petshop.pojo.Result;
import com.pets.springboot_petshop.service.PettypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: wxk
 * @Email: 2089967794@qq.com
 * @Date: 2024/10/12 上午9:56 周六
 * @Description: 宠物类型控制层
 */
@RestController
@RequestMapping("/Pettype")
public class PettypeController {
    @Autowired
    private PettypeService pettypeService;

    @GetMapping("/selectPettype")
    public Result selectPettype(@RequestParam int id) {
        Pettype pettype = pettypeService.selectPettype(id);
        if (pettype != null) {
            return Result.success(pettype);
        }else {
            return Result.error("获取失败");
        }
    }
    @GetMapping("/selectName")
    public Result selectName(@RequestParam String name) {
        Pettype pettype = pettypeService.selectPettypename(name);
        if (pettype != null) {
            return Result.success(pettype);
        }else {
            return Result.error("获取失败");
        }
    }
    @GetMapping("/findAll")
    public Result findAll() {
        List<Pettype> pettype = pettypeService.findAll();
        if (pettype != null) {
            return Result.success(pettype);
        }else {
            return Result.error("获取失败");
        }
    }
    @PostMapping("/addPettype")
    public Result addPettype(@RequestBody Pettype pettype) {
        if (pettypeService.addPettype(pettype) > 0) {
            return Result.success("新增成功");
        }else {
            return Result.error("新增失败");
        }
    }
    @PostMapping("/deletePettypeById")
    public Result deletePettypeById(@RequestParam int id) {
        if (pettypeService.deletePettypeById(id) > 0) {
            return Result.success("删除成功");
        }else {
            return Result.error("删除失败");
        }
    }
    @PostMapping("updatePettypeById")
    public Result updatePettypeById(@RequestBody Pettype pettype) {
        if (pettypeService.updatePettypeById(pettype) > 0) {
            return Result.success("修改成功");
        }else{
            return Result.error("修改失败");
        }
    }

}
